package program.Condition;

import program.SExpression;
import Exceptions.IllegalCoordinateException;
import roborally.Element;
import roborally.Position;
import roborally.Robot;

/**
 * A class representing a WALL condition.
 * 
 * @author Jef Keijers/Bachelor of Science: Informatics
 * @version 1.0
 */
public class Wall extends Condition {

	/**
	 * This method returns true if there's a wall to the right of the given robot, otherwise it returns false.
	 */
	@Override
	public boolean execute(Robot robot) throws IllegalCoordinateException {
		Position rightNextToRobot=new Position(robot.getPosition().getX()+1,robot.getPosition().getY(),robot.getBoard());
		for (Element element: robot.getBoard().getPositionMap().get(rightNextToRobot)) {
			if (element instanceof roborally.Wall) 
				return true;
		}
		return false;
	}

	/**
	 * This method returns the SExpression representation of wall.
	 */
	@Override
	public SExpression toSExpression() {
		return this.makeSingletonSExpressionList("wall");
	}
}
